package com.cai.kcsj.controller.pre;

import com.cai.kcsj.entity.Comtent;
import com.cai.kcsj.entity.User;
import com.cai.kcsj.service.ComtentServer;
import com.cai.kcsj.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @version 1.0
 * @author：蔡松坡
 * @date：2021/1/5 19 : 07
 * @package：com.cai.kcsj.controller.pre
 */
@Controller
@RequestMapping("/precom")
public class PreComtentController {
    @Autowired
    private ComtentServer comtentServer;

    @RequestMapping("/addComtent")
    public  String add(HttpServletRequest request, Model model,Comtent comtent){
        User user = (User) request.getSession().getAttribute("user");
        Integer id = user.getId();
        comtent.setUserid(id);
        comtent.setCtime(DateUtil.getDate());
        comtentServer.addComtent(comtent);
        List<Comtent> comtents = comtentServer.selectComById(comtent.getGoodsid());
        model.addAttribute("comtentsList",comtents);
        return "redirect:/preindex/onlygoods/"+comtent.getGoodsid();
    }
}
